<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>项目分配</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../js/formSelects/formSelects-v4.css">
    <style>
        legend{
            color: #00c0ef
        }
    </style>
</head>
<body>
<div style="margin-top: 40px; margin-right: 30px;">
    <form class="layui-form" action="" lay-filter="dataForm">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>项目信息</legend>
        </fieldset>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-block" style="width: 350px">
                    <input type="text" name="projectname"  id="projectname" placeholder="项目名称" readonly class="layui-input">
                    <input type="text" name="projectid" id="projectid" style="display: none">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">项目类型</label>
                <div class="layui-input-block" style="width: 350px">
                    <input type="text" name="projecttype"  placeholder="项目类型" readonly class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">项目地址</label>
                <div class="layui-input-block" style="width: 350px">
                    <input type="text" name="projectadress"  placeholder="项目地址" readonly class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">工程状态</label>
                <div class="layui-input-block" style="width: 350px">
                    <input type="text" name="projectstatus"  placeholder="工程状态" readonly class="layui-input">
                </div>
            </div>
        </div>


        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
            <legend>信息填写</legend>
        </fieldset>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>劳务公司名称</label>
            <div class="layui-input-block" >
                <select name="companyid"  id="companyid" xm-select="companyid" lay-verify="required"   lay-search="">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="description" id="description" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
            <legend>信息提交</legend>
        </fieldset>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button id="btnSub" class="layui-btn" lay-filter="formSubmit"  lay-submit="">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="../assets/layui/layui.js"></script>
<script>
    layui.config({
        base: '../js/'
    })
        .extend({
            formSelects: 'formSelects/formSelects-v4'
        });
    layui.use(['jquery','form','common','formSelects'], function () {
        var form = layui.form,
            $ = layui.jquery,
            formSelects = layui.formSelects,
            common = layui.common;
        var id = common.getUrlParam("id");

        formSelects.config("companyid",{
            keyName: 'name',
            keyVal: 'code'})
            .data("companyid","server",{
                url: '../company/dd4Company?hasAll=1',
                success: function(id, url, searchVal, result){
                    formSelects.value('companyid',result);
                }
            });

        //针对已选择过的劳务公司赋值
        $.ajax({
            url: "../builder/companys",
            dataType: "json",
            data: { projectId: id },
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    formSelects.value('companyid',rtn.data.split(','));
                }
            }
        });
        form.render('select');
        formSelects.render();
        //获取用户信息
        $.ajax({
            url: "info",
            dataType: "json",
            data: { projectId: id },
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    var data = rtn.data;
                    form.val('dataForm',{
                        projectname:data.projectname,
                        projectid:data.projectid,
                        projecttype:data.projecttype,
                        projectadress:data.projectadress,
                        projectstatus:data.projectstatus,
                    });
                }
            }
        });

        form.on('submit(formSubmit)', function (data) {
            data.field.project_id = $("#projectid").val();
            data.field.company_id = formSelects.value('companyid', 'valStr');
            data.field.description = $("#description").val();
            $.ajax({
                type: 'post',
                url: '../builder/addProComRes',
                data: {json: JSON.stringify(data.field)},
                success: function (rtn) {
                    if (rtn.code === 0) {  //数据保存成功
                        var msg = "保存成功!";
                        common.showInfo(msg, function () {
                            //刷新前页
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.document.getElementById('btnSearch').click();
                            parent.layer.close(index);
                        });
                    }
                    else {
                        common.showError(rtn.msg);
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    common.showError('保存错误');
                }
            });
            return false;
        });
    })
</script>
</body>
</html>